FROM repository.bitwitsoft.com:80/library/node:18.19.0 AS build-stage
# FROM repository.bitwitsoft.com/library/node:18.19.0-alpine AS build-stage
ARG NPM_REGISTRY
ARG NPM_TOKEN
ARG WEB_VERSION

WORKDIR /app

# RUN npm i -g pnpm
# RUN npm i -g cross-env
# RUN npm i -g esno@4.7.0

RUN echo "registry=http://registry.npmmirror.com" > .npmrc
RUN echo "@bitwit:registry=http://${NPM_REGISTRY}/" >> .npmrc
RUN echo "//${NPM_REGISTRY}/:_authToken=${NPM_TOKEN}" >> .npmrc

COPY package.json ./

RUN pnpm install

COPY . .

RUN npm version ${WEB_VERSION}

# 设置环境变量
# 版本号
ENV VERSION = ${WEB_VERSION}

ENV NODE_ENV=production

RUN pnpm cross-env NODE_ENV=production NODE_OPTIONS=\"--max-old-space-size=102400\" vite build
RUN esno ./build/script/postBuild.ts

FROM repository.bitwitsoft.com:80/library/nginx:1.20.2 as production-stage
# FROM repository.bitwitsoft.com/library/nginx:1.20.2 as production-stage

COPY --from=build-stage /app/dist /usr/share/nginx/html

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
